<extend name="Public/base"/>

<block name="body">
    <link type="text/css" rel="stylesheet" href="__PUBLIC__/Core/js/ext/magnific/magnific-popup.css"/>
    <!-- 标题 -->
    <div class="main-title">
        <h2>
            {$title|htmlspecialchars}
        </h2>
    </div>
    <div class="combiner_hook">
        {$combiner_hook_title_bottom}
    </div>

    <div class="combiner_hook">
        {$combiner_hook_search_top}
    </div>	
    <php>
        foreach($searches as $search){
            if($_REQUEST[$search['name']])
        {
        $show=1;
        }
        }
    </php>

    <div style="margin-bottom: 10px;display:<php>echo count($searches)>0?'block':'none';</php>" id="search_form" >

        <style>
            .tb_search td{
                padding: 5px 10px;
            }
        </style>
<form id="searchForm" method="post" action="{$searchPostUrl}" class="form-dont-clear-url-param">
    <div class="search-form  cf " style="margin-bottom: 10px">
        <table class="tb_search">
      <tr style="line-height: 28px">
    <volist name="searches" id="search">
  
                <if condition="$search['type'] eq 'text'">
              
                  <td>
                      {$search.title}:
                  </td>
                  <td>
				     
                         <input style="float: none;border:1px solid #cccccc;width:150px" type="text" name="{$search.name}" class="text form-control"
                             value="{:I($search['name'])}">
					  
                      
							 
                  </td>
                  <td>
                      {$search.des}
                  </td>
                <elseif condition="$search.type eq 'time'" />
              
                  <td>
                      {$search.title}:
                  </td>
                  <td>
				         <input type="hidden" name="{$search.name}" value="{:I($search['name'])}"/>
                        <input type="text" data-field-name="{$search.name}" style="float: none;border:1px solid #cccccc;width:150px" class="text form-control time" value="<php>if(!empty(I($search['name']))){echo time_format(I($search['name']),'Y-m-d');}</php>" placeholder="请选择时间" />
                        
							 
                  </td>
                  <td>
                      {$search.des}
                  </td>
                <elseif condition="$search.type eq 'hidden'" />
				  <td>
				   <input style="float: none;border:1px solid #cccccc" type="hidden" name="{$search.name}" class="text form-control"
                             value="{:I($search['name'])}">
				  </td>			 
                </if>	
    </volist>
	 
               <td></td>
                <td><input type="submit" class="btn" value="搜索"/> <button class="btn ajax-post btn" onclick="toggle_search()" style="display:none">关闭</button></td>
                <td></td>
            </tr>
    </table>
        </div>
        </form>
        <div style="border-top:1px solid #ccc;border-bottom: 1px solid white"></div>
    </div>
    <!-- 按钮工具栏 -->
    <div class="cf">
        <div class="fl">
<if condition="count($searches) gt 0">
    <button class="btn submit-btn" url="?status=-1" target-form="ids" style="padding: 6px 16px;display:none" onclick="toggle_search()">搜索</button>

</if>

            <volist name="buttonList" id="button">
                <{$button.tag} {$button.attr}>{$button.title|htmlspecialchars}</{$button.tag}>
            </volist>
        </div>
    </div>

    <!-- 数据表格 -->
    <div class="data-table">
        <table>
            <!-- 表头 -->
            <thead>
            <tr>
                <th class="row-selected row-selected">
                    <input class="check-all" type="checkbox"/>
                </th>
                <volist name="keyList" id="field">
                    <th>
					  <if condition="$field.name eq 'sort'">
                         <button class="btn submit-btn" url="?status=-1" target-form="ids" style="padding: 6px 16px;" onclick="$('#sortform').submit()">{$field.title|htmlspecialchars}</button>
					  <else /> 
					    {$field.title|htmlspecialchars}
                      </if>					
					</th>
                </volist>
            </tr>
            </thead>

            <!-- 列表 -->
			<form action="{:U('editsort')}" method="post" id="sortform">
            <tbody>
            <volist name="list" id="e">
                <tr>
                    <td><input class="ids" type="checkbox" value="{$e['id']}" name="ids[]"></td>
                    <volist name="keyList" id="field">
                        <td>
						<if condition="$field.name eq 'sort'">
						   <input type="number" style="border:1px solid #c9c9c9;-webkit-border-radius: 3px;-moz-border-radius: 3px;border-radius:3px;width:45px;height:23px;text-align:center" value="{$e[$field['name']]}" name="sort{$e['id']}">

						<else /> 
						   {$e[$field['name']]}
                        </if>	
						</td>
                    </volist>
                </tr>
            </volist>
            </tbody>
			</form>
        </table>
    </div>
    <!-- 分页 -->
    <div class="page">
        {$pagination}
    </div>
    </div>

    <script type="text/javascript" src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">
//        //搜索功能
//        $("#search").click(function () {
//            var url = $(this).attr('url');
//            var query = $('.search-form').find('input').serialize();
//            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
//            query = query.replace(/^&/g, '');
//            if (url.indexOf('?') > 0) {
//                url += '&' + query;
//            } else {
//                url += '?' + query;
//            }
//            window.location.href = url;
//        });
        //回车搜索
//        $(".search-input").keyup(function (e) {
//            if (e.keyCode === 13) {
//                $("#search").click();
//                return false;
//            }
//        });
        function toggle_search(){
            $('#search_form').toggle('slide');
        }


        $(document).on('submit', '.form-dont-clear-url-param', function(e){
            e.preventDefault();

            var seperator = "&";
            var form = $(this).serialize();
            var action = $(this).attr('action');
            if(action == ''){
                action = location.href;
            }
            var new_location = action + seperator + form;

            location.href = new_location;

            return false;
        });


    </script>


    <script>
        $(function(){
            $('.tox-confirm').click(function(e){
                var text = $(this).attr('data-confirm');
                var result = confirm(text);
                if(result) {
                    return true;
                } else {
                    e.stopImmediatePropagation();
                    e.stopPropagation();
                    e.preventDefault();
                    return false;
                }
            })
			
			$('.time').datetimepicker({
                format: 'yyyy-mm-dd',
                language:"zh-CN",
                minView:2,
                autoclose:true
            });

            $('.time').change(function(){
                var fieldName = $(this).attr('data-field-name');
                var dateString = $(this).val();
                var date = new Date(dateString);
                var timestamp = date.getTime();
                $('[name='+fieldName+']').val(Math.floor(timestamp/1000));
            });
        });


        $(document).ready(function () {

            $('.popup-gallery').each(function () { // the containers for all your galleries
                $(this).magnificPopup({
                    delegate: 'a',
                    type: 'image',
                    tLoading: '正在载入 #%curr%...',
                    mainClass: 'mfp-img-mobile',
                    gallery: {
                        enabled: true,
                        navigateByImgClick: true,
                        preload: [0, 1] // Will preload 0 - before current, and 1 after the current image

                    },
                    image: {
                        tError: '<a href="%url%">图片 #%curr%</a> 无法被载入.',
                        titleSrc: function (item) {
                            /*           return item.el.attr('title') + '<small>by Marsel Van Oosten</small>';*/
                            return '';
                        },
                        verticalFit: false
                    }
                });
            });
        });
    </script>
    <script type="text/javascript" src="__PUBLIC__/Core/js/ext/magnific/jquery.magnific-popup.min.js"></script>
</block>